﻿@{
    ViewBag.Title = "UserEdit";
}
@model CRM.Admin.Contracts.Dto.Sys.UserInfoDto
@section head
{
    <script src="@Url.Content("~/ScriptPlugin/WdatePicker/js/WdatePicker.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Scripts/form2json.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Scripts/py.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/ScriptPlugin/webuploader/webuploader.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Scripts/KingsSharp.Uploader.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Scripts/jquery.validate.min.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Scripts/jquery.validate.extended.js")"></script>
    <script src="@Url.Content("~/Scripts/jquery.linq.min.js")"></script>
}
<form action="" id="userform">
    <div class="content-form">
        <table class="content-table">
            <tr>
                <th><span>用户名称</span></th>
                <td>
                    <input type="text" value="@Model.Name" onblur="GetLoginCode()" maxlength="20" data-valid="required" id="Name" name="Name" />
                </td>
                <th><span>登录帐号</span></th>
                <td>
                    <input type="text" id="LoginCode"
                           data-validate-option="isNull"
                           name="LoginCode" maxlength="30" readonly="readonly" title="编辑时无法修改" value="@Model.LoginCode" />
                </td>
                <th>密码</th>
                <td>
                    <input type="text" value="编辑时无法需改" disabled="disabled" data-valid="required" id="NoEditPassword" name="NoEditPassword" />
                </td>
                <th>排序号</th>
                <td><input type="text" value="@Model.Order" id="Order" name="Order" onkeypress="K.OnlyNum()" /></td>
            </tr>
            <tr>
                <th>性别</th>
                <td>
                    <select id="Sex" name="Sex">
                        @{
                            if(Model.Sex=="男")
                            {
                               <option selected="selected">男</option>
                                <option>女</option> 
                            }
                            else
                            {
                                <option>男</option>
                                 <option selected="selected">女</option>
                            }
                            }
                    </select>
                </td>
                <th>年龄</th>
                <td>
                    <input type="text" value="@Model.Age" id="Age" maxlength="3" name="Age" data-valid="required number" onkeypress="K.OnlyNum()" />
                </td>
                <th>生日</th>
                <td>
                    <input type="text" value="@Model.Birthday" id="Birthday" readonly="readonly" name="Birthday" class="p-icon-right p-icon-date" />
                </td>
                <th rowspan="2">头像</th>
                <td rowspan="2">
                    <input type="hidden" id="PortraitURL" name="PortraitURL" value="@Model.PortraitURL" />
                    <div style="float:left" id="userpic">
                        @if(string.IsNullOrWhiteSpace(Model.PortraitURL))
                        {
                            <img src="@Url.Content("~/Images/noportrait.png")" style="width:40px;height:40px" />
                        }
                        else
                        {
                            <img src="@Url.Content("~/" + Model.PortraitURL)" style="width:40px;height:40px" />
                        }
                    </div>
                    <div id="picker" style="float:left;width:auto">
                        <button type="button" class="u-btn u-btn-c4"
                                style="height:22px;line-height:22px;margin-left:15px;margin-top:10px">
                            选择...
                        </button>
                    </div>
                </td>
            </tr>
            <tr>
                <th>身份证号</th>
                <td>
                    <input type="text" value="@Model.IdNumber" maxlength="22" id="IdNumber" name="IdNumber" />
                </td>
                <th>手机</th>
                <td>
                    <input type="text" value="@Model.Phone" maxlength="15" id="Phone" name="Phone" />
                </td>
                <th>座机</th>
                <td>
                    <input type="text" value="@Model.Tel" maxlength="15" id="Tel" name="Tel" />
                </td>
            </tr>
            <tr>
                <th>授权角色</th>
                <td colspan="7">
                    <input type="text" readonly="readonly" value="@Model.RoleNames" id="RoleNames" name="RoleNames" class="p-icon-right p-icon-role" onclick="GetRoles(this)" />
                    <input type="hidden" id="RoleIds" name="RoleIds" value="@Model.RoleIds" />
                </td>
            </tr>
            <tr>
                <th>签名</th>
                <td colspan="7">
                    <input type="text" value="@Model.Signature" maxlength="100" id="Signature" name="Signature" />
                </td>
            </tr>
            <tr>
                <th>备注</th>
                <td colspan="7">
                    <input type="text" value="@Model.Remark" maxlength="500" id="Remark" name="Remark" />
                    <input type="hidden" value="@Model.Id" id="Id" name="Id" />
                </td>
            </tr>
        </table>
    </div>
</form>
@section foot
{
    <script type="text/javascript">
       function GetLoginCode()
       {
         var name = $("#Name").val();
         if(name!="")
         {
             $("#LoginCode").val(KingsSharp.Pinyin(name))
         }
       }
       function GetRoles()
       {
           K.layer.iframe({
               title: "@Html.GetLayerTitle(LayerIcon.Add,"选择授权角色")",
               content: "@Url.Content("~/Sys/Role/RoleCheck")",
               maxmin: true,
               area: ["480px", "340px"],
               callback: function (checkedRows) {
                   var Ids = new Array(), Names = new Array();
                   $.Enumerable.From(checkedRows).ForEach(function (row, i) {
                       Ids.push(row.Id);
                       Names.push(row.Name);
                   });
                   $("#RoleNames").val(Names.join(','));
                   $("#RoleIds").val(Ids.join(','));
               }
           });
       }
       function SaveData(index) {
           if ($("#userform").valid()) {
               var dto = KingsSharp.Form2Json();
               K.AjaxJson("@Url.Content("~/Sys/User/UserUpdate")", { dtos: dto }, function (result) {
                   parent.K.layer.callback(index, result, dto);
                   parent.K.layer.close(index);
               });
           }
       }
        var uploader = new K.Uploader().createImage({
            swf: '@Url.Content("~/ScriptPlugin/webuploader/Uploader.swf")',
            server: '@Url.Content("~/Sys/User/UploaderProcess")',
            pick: '#picker',
            resize: false,
            auto: true
        }, {
            fileQueued: function (file) {
                uploader.makeThumb(file, function (error, ret) {
                    if (error) {
                        $("#userpic").html("预览错误");
                    } else {
                        $("#userpic").html("");
                        $("#userpic").append("<img src=\"" + ret + "\" alt=\"\" style=\"width:40px;height:40px\" />");
                    }
                });
            },
            uploadSuccess: function (file, response) {
                if (response.Filish) {
                    $("#PortraitURL").val(response.Path);
                }
            },
            uploadError: function () {
                K.Alert("头像上传出错");
            }
        });
    </script>
}